﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArchiveLink
{
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Security.AccessControl;
    using System.Threading;
    using System.Xml.Serialization;
    using Microsoft.WindowsAPICodePack.Shell;
    using Splicer.Renderer;
    using Splicer.Timeline;

    public class Linker
    {



        private Dictionary<string, LinkedDrive> _linkedDrives;
        private ILogger _logger;


        private DriveWatcher DriveWatcher { get; set; }

        private Configuration Config
        {
            get
            {
                if (Properties.Settings.Default.Configuration == null)
                {
                    Properties.Settings.Default.Configuration = new Configuration();
                    Properties.Settings.Default.Save();
                }
                return Properties.Settings.Default.Configuration;
            }
        }

        public Linker(ILogger logger)
        {
            _logger = logger;
        }




        public void StartDriveWatcher()
        {
            DriveWatcher = new DriveWatcher();
            var mirrorDir = new DirectoryInfo(Config.MirrorPath);
            var linkedDriveNames = mirrorDir.GetDirectories();
            _linkedDrives = new Dictionary<string, LinkedDrive>();

            foreach (var driveName in linkedDriveNames)
            {
                if (driveName.Name != "_Offline")
                {
                    _linkedDrives.Add(driveName.Name, new LinkedDrive(driveName.Name, DriveWatcher, Config, _logger));
                }
            }

            foreach (var linkedDrive in _linkedDrives)
            {
                linkedDrive.Value.Sync();
            }

            DriveWatcher.InitDiskEvent(Config.ConsiderOpticalDisks);
        }


    }
}
